/*
 * 创建日期 2010-1-4
 *
 * 成都天和软件公司
 * 电话：028-85425861
 * 传真：028-85425861-8008
 * 邮编：610041 
 * 版权所有
 */
package  org.fantasy.common.grid.export;

import  org.fantasy.common.grid.bean.ReportParam;
import  org.fantasy.common.grid.report.ReportBuilder;
import  org.fantasy.common.grid.report.ReportBuilderFactory;
import  org.fantasy.common.util.Request;
import  org.fantasy.common.util.RequestUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

/**
 *  导出Excel
 * @author: 王文成
 * @version: 1.0
 * @since 2010-1-4
 */
public class ExportPOIExcel extends BaseExport {

    /**
     * 导出Excel
     * 
     * @param servletRequest
     * @param response
     * @throws Exception
     */
    @Override
    public void export(HttpServletRequest servletRequest, HttpServletResponse response) throws Exception {
        Request request = RequestUtil.getWrapRequest(servletRequest);
        ReportParam param = getExportParam(request);
        ReportBuilder builder = ReportBuilderFactory.getPOIExcelBuilder(param);
        HSSFWorkbook workbook = (HSSFWorkbook) builder.getReport();
        String encodeFileName = getFileName(request, param);
        if (!response.isCommitted())
            response.reset();
        response.setHeader("Pragma", "");
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Content-Type", "application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment; filename=" + encodeFileName + ".xls");
        workbook.write(response.getOutputStream());
    }
}
